1
using System
.Collections
;
2 using System
.Collections
.Generic
;
5 public class YarnMovement
: MonoBehaviour
{
10 LayerMask whatIsGround
;
13 private Animator anim
;
14 private Rigidbody2D rb
;
15 private Vector2 facingDirection
;
16 private float groundCheckRadius
= 0.1f
;
17 private Transform groundCheck
;
18 private Transform spriteChild
;
20 private bool isRolling
;
21 private bool grounded
;
24 anim
= GetComponent
<Animator
> ();
25 rb
= GetComponent
<Rigidbody2D
> ();
26 groundCheck
= transform
.Find ("GroundCheck");
27 spriteChild
= transform
.Find ("OutsideSprite");
28 facingDirection
= Vector2
.right
;
41 Collider2D
[] colliders
= Physics2D
.OverlapCircleAll (groundCheck
.position
, groundCheckRadius
, whatIsGround
);
42 foreach (Collider2D col
in colliders
) {
43 if (col
.gameObject
!= gameObject
) {
54 if (Input
.GetButton ("Left")) {
55 transform
.Translate (-Vector2
.right
* moveSpeed
* Time
.deltaTime
);
56 FaceDirection (-Vector2
.right
);
59 if (Input
.GetButton ("Right")) {
60 transform
.Translate (Vector2
.right
* moveSpeed
* Time
.deltaTime
);
61 FaceDirection (Vector2
.right
);
66 void FaceDirection(Vector2 direction
)
68 Quaternion rotation3D
= direction
== Vector2
.right
? Quaternion
.LookRotation (Vector3
.forward
) : Quaternion
.LookRotation (Vector3
.back
);
69 spriteChild
.rotation
= rotation3D
;
72 void updateAnimation()
74 anim
.SetBool ("isRolling", isRolling
);